/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socketsudp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author epulapp
 */
public class Serveur extends Thread{
    
    public Serveur(){
    
    }
    
    @Override 
    public void run(){
        try {
            byte[] data = new byte[8192];
           DatagramSocket s = new DatagramSocket(8080);;
           DatagramPacket p;

           System.out.println("Ici serveur (thread " + Thread.currentThread().getId() + ").");
           
           while (true) {
               p = new DatagramPacket(data, data.length);
               s.receive(p);
               Thread myThread = new Communication(p);
               myThread.start();
               System.out.println("Le message a ete traite : " + new String(p.getData(), "ASCII"));
           }
        } catch (IOException ex) {
            Logger.getLogger(Serveur.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args){
       Serveur myServ = new Serveur();
       myServ.start();
    } // main()
} // Serveur
